home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / sendmail / sendmail-5.65c+IDA-1.4.4.1 / uiuc / dconn.c next >
Encoding:
C/C++ Source or Header  |  1989-05-23  |  1.5 KB  |  73 lines

  1. /* dconn is the Decnet Connect program. The intention is that
  2. ** it will open a decnet socket (stream) and transfer stdin to that
  3. ** while everything from the connection goes to that.
  4. **
  5. ** sendmail can then use that with an entry like
  6. **
  7. ** MDsmtp, P=/usr/lib/mail/dconn, F=msDFMueXLR, S=13, R=24, E=\r\n,
  8. **    A=dconn #130 $h
  9. **
  10. ** because there is no $u in the arguments, sendmail will talk smtp to it.
  11. */
  12. #include <stdio.h>
  13. #include <signal.h>
  14.  
  15. #include <sys/syslog.h>
  16. #include <netdnet/dn.h>
  17. #include <sys/types.h>
  18. #include <sys/socket.h>
  19.  
  20. #define DEBUG 1
  21.  
  22. extern int    errno;
  23. int        me;
  24.  
  25. bye (str, i)
  26.     int        i;
  27.     char           *str;
  28. {
  29.     if (DEBUG || i != 0)
  30.         printf ("%d: why %s, exit %d, errno=%d\r\n",
  31.             me, str, i, errno);
  32.     exit (i);
  33. }
  34.  
  35. main (argc, argv)
  36.     int        argc;
  37.     char           *argv[];
  38.  
  39. {
  40.     register int    dcr, i, j;
  41.     char           *pnt;
  42.     static char    fromdn[512], todn[512];
  43.     char           *index ();
  44.  
  45.     if (argc != 3)
  46.         bye ("not enuf args", 5);
  47.  
  48.     if ((pnt = index (argv[2], '.')) != (char *) NULL)
  49.         *pnt = '\0';
  50.     dcr = dnet_conn (argv[2], argv[1], SOCK_STREAM, 0, 0, 0, 0);
  51.  
  52.     if (dcr == -1)
  53.         bye ("dnet_conn failed", 1);
  54.  
  55.     switch (me = fork ()) {
  56.         case 0:        /* kid */
  57.         close (1);
  58.         while ((i = read (0, todn, 512)) > 0) {
  59.             if (i != write (dcr, todn, i))
  60.                 bye ("write failed", 2);
  61.         }
  62.         bye (i);
  63.         case -1:        /* Error */
  64.         bye ("fork failed", 4);
  65.         default:        /* parent! */
  66.         close (0);
  67.         while ((j = read (dcr, fromdn, 512)) > 0) {
  68.             if (j != write (1, fromdn, j))
  69.                 bye ("2nd write failed", 3);
  70.         }
  71.     }
  72. }
  73.